//
// Copyright (c) 2011 Alex Nesterenko
//

#ifndef NANE_OGLXWINDOWCONTEXT_H
#   define  NANE_OGLXWINDOWCONTEXT_H

#   include "nane/RenderSystem/ogl/OGLWindowContext.h"
#   include "nane/core/crt/DynamicModule.h"
#   include <X11/Xlib.h>
#   include <X11/Xutil.h>

extern "C"
{
    typedef void* GLXContext;
    typedef Window GLXDrawable;
    typedef XVisualInfo* (*PFUNCGLXCHOOSEVISUAL)(Display*, int, int*);
    typedef GLXContext (*PFUNCGLXCREATECONTEXT)(Display*, XVisualInfo*, GLXContext, Bool);
    typedef Bool (*PFUNCGLXMAKECURRENT)(Display*, GLXDrawable, GLXContext);
    typedef void (*PFUNCGLXDESTROYCONTEXT)(Display*, GLXContext);
    typedef void (*PFUNCGLXSWAPBUFFERS)(Display*, GLXDrawable);
    typedef Bool (*PFUNCGLXQUERYEXTENSION)(Display*, int*, int*);
}

namespace nane
{
    class OGLXWindowContext
        : public OGLWindowContext
    {
    public:
        OGLXWindowContext();
        ~OGLXWindowContext();

    public:
        bool initialize( IWindow::OSHandle _windowHandle );
        void shutdown();
        void swapBuffers();

    private:
        IWindow::OSHandle m_windowHandle;
        Display* m_display;
        ModuleHandle* m_hOpenGL;
        GLXContext m_hGLContext;
        Window m_hSubWindow;
        PFUNCGLXCHOOSEVISUAL m_pGLXChooseVisual;
        PFUNCGLXCREATECONTEXT m_pGLXCreateContext;
        PFUNCGLXMAKECURRENT m_pGLXMakeCurrent;
        PFUNCGLXDESTROYCONTEXT m_pGLXDestroyContext;
        PFUNCGLXSWAPBUFFERS m_pGLXSwapBuffers;
        PFUNCGLXQUERYEXTENSION m_pGLXQueryExtension;
    };
}   // namespace nane

#endif	// NANE_OGLXWINDOWCONTEXT_H
